package com.im.gate;

import com.im.gate.codec.MessageDecoder;
import com.im.gate.codec.MessageEncoder;
import com.im.gate.server.ServerMessageHandler;
import com.rou.im.boot.starter.server.ChannelInitializerPostProcessor;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * <p></p>
 *
 * @author GaoShuangWen
 * @since 2020-05-04 14:19
 */
@Component
public class ChannelInitializerBean implements ChannelInitializerPostProcessor {

    @Autowired
    private ServerMessageHandler handler;

    @Override
    public void initChannelPostProcessor(Channel ch) {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new MessageDecoder());
        pipeline.addLast(new MessageEncoder());
        pipeline.addLast(handler);
    }
}
